package com.bjpowernode.boss.mvc.controller;

import com.bjpowernode.boss.mvc.models.AjaxResult;
import com.bjpowernode.boss.mvc.models.dto.operator.LoginResponseDto;
import com.bjpowernode.boss.mvc.models.form.operator.LoginForm;
import com.bjpowernode.boss.mvc.models.menus.SubMenu;
import com.bjpowernode.boss.mvc.service.OperatorService;
import jakarta.annotation.Resource;
import lombok.Getter;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Mrs.cui
 * 2024-07-07-21-09
 */
@CrossOrigin
@RestController
@RequestMapping("/operator")
public class OperatorController {

    @Resource
    private OperatorService operatorService;

    //登录，获取token
    @PostMapping("/login")
    public AjaxResult operatorLogin(@RequestBody @Validated LoginForm loginForm) {

        //进行登录，生成jwt
        LoginResponseDto loginResponseDto = operatorService.operatorLogin(loginForm);

        //返回Dto给前端
        return AjaxResult.ok(loginResponseDto);
    }

    //根据登录用户获取菜单列表
    @GetMapping("/menus")
    public AjaxResult getMenus(@RequestHeader("operatorId") Long operatorId) {

        //调用service获取菜单
        List<SubMenu> subMenuList = operatorService.getMenuByLoginUser(operatorId);
        return AjaxResult.ok(subMenuList);
    }
}
